home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / POLCOF.DEM < prev    next >
Text File  |  1991-04-29  |  2KB  |  66 lines

  1. PROGRAM d3r8 (input,output);
  2. (* driver for routine POLCOF *)
  3. LABEL 1;
  4. CONST
  5.    np=5;
  6.    pi=3.1415926;
  7. TYPE
  8.    glnarray = ARRAY [1..np] OF real;
  9. VAR
  10.    i,j,nfunc : integer;
  11.    f,sum,x : real;
  12.    coeff,xa,ya : glnarray;
  13.  
  14. (*$I MODFILE.PAS *)
  15. (*$I POLINT.PAS *)
  16.  
  17. (*$I POLCOF.PAS *)
  18.  
  19. BEGIN
  20.    FOR nfunc := 1 to 2 DO BEGIN
  21.       IF (nfunc = 1) THEN BEGIN
  22.          writeln;
  23.          writeln ('sine function from 0 to pi');
  24.          FOR i := 1 to np DO BEGIN
  25.             xa[i] := i*pi/np;
  26.             ya[i] := sin(xa[i])
  27.          END
  28.       END ELSE IF (nfunc = 2) THEN BEGIN
  29.          writeln;
  30.          writeln ('exponential function from 0 to 1');
  31.          FOR i := 1 to np DO BEGIN
  32.             xa[i] := 1.0*i/np;
  33.             ya[i] := exp(xa[i])
  34.          END
  35.       END ELSE BEGIN
  36.          GOTO 1
  37.       END;
  38.       polcof(xa,ya,np,coeff);
  39.       writeln;
  40.       writeln ('  coefficients');
  41.       FOR i := 1 to np DO BEGIN
  42.          writeln (coeff[i]:12:6)
  43.       END;
  44.       writeln;
  45.       writeln ('x':9,'f(x)':13,'polynomial':15);
  46.       FOR i := 1 to 10 DO BEGIN
  47.          IF (nfunc = 1) THEN BEGIN
  48.             x := (-0.05+i/10.0)*pi;
  49.             f := sin(x)
  50.          END ELSE IF (nfunc = 2) THEN BEGIN
  51.             x := -0.05+i/10.0;
  52.             f := exp(x)
  53.          END;
  54.          sum := coeff[np];
  55.          FOR j := np-1 DOWNTO 1 DO BEGIN
  56.             sum := coeff[j]+sum*x
  57.          END;
  58.          writeln (x:12:6,f:12:6,sum:12:6)
  59.       END;
  60.       writeln ('************************************');
  61.       writeln ('press RETURN');
  62.       readln
  63.    END;
  64. 1:
  65. END.
  66.